﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace InControl
{
    public partial class INV_editpeople_form : Form
    {
        private List<string> ls;

        public INV_editpeople_form()
        {
            InitializeComponent();
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void INV_editpeople_form_Load(object sender, EventArgs e)
        {
            ((INV_MDIParent)this.MdiParent).appDriver.FillTable(dataGridView2, "-2");
            if (((INV_MDIParent)this.MdiParent).appDriver.group != "administrators")
            {
                textBox1.ReadOnly = true; textBox2.ReadOnly = true; textBox3.ReadOnly = true; textBox5.ReadOnly = true;
                textBox7.ReadOnly = true; textBox4.ReadOnly = true; textBox6.ReadOnly = true; textBox8.ReadOnly = true;
                textBox11.ReadOnly = true;
            }
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label19_Click(object sender, EventArgs e)
        {
            panel4.Visible = true;
            panel5.Visible = false;
            panel6.Visible = false;
            panel7.Visible = false;
        }

        private void label2_Click(object sender, EventArgs e)
        {
            panel4.Visible = false;
            panel5.Visible = true;
            panel6.Visible = false;
            panel7.Visible = false;
        }

        private void label20_Click(object sender, EventArgs e)
        {
            panel4.Visible = false;
            panel5.Visible = false;
            panel6.Visible = true;
            panel7.Visible = false;
        }

        private void label21_Click(object sender, EventArgs e)
        {
            textBox9.Clear(); textBox10.Clear();
            panel4.Visible = false;
            panel5.Visible = false;
            panel6.Visible = false;
            panel7.Visible = true;
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            try
            {
                if (panel9.Visible == true)
                {
                    Console.WriteLine("ah whoa");
                    throw new Exception("no user selected");
                }

                if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "" && textBox5.Text != "" && 
                    textBox10.Text != "" && textBox7.Text != "" && textBox9.Text != "" )
                {
                    if (textBox9.Text != textBox10.Text)
                    {
                        textBox9.BackColor = Color.LightCoral; textBox10.BackColor = Color.LightCoral; 
                        throw new Exception("ERROR: \nPassword mismatch");
                    }       
                    /* String fname, String lname, String mname, String title, String ext, String mobile, String ework, String epersonal, String passw */
                    ((INV_MDIParent)this.MdiParent).appDriver.UpdateEmployee(dataGridView2.CurrentRow.Cells["id"].Value.ToString(), textBox1.Text, textBox2.Text, textBox3.Text, textBox11.Text, textBox5.Text, textBox6.Text, textBox7.Text, textBox8.Text, textBox9.Text);
                    Error_form ef = new Error_form();
                    ef.richTextBox1.Text = "update successful";
                    ef.ShowDialog(this);
                }
                else
                {
                    textBox1.BackColor = Color.LightCoral; textBox2.BackColor = Color.LightCoral; textBox3.BackColor = Color.LightCoral;
                    textBox5.BackColor = Color.LightCoral; textBox7.BackColor = Color.LightCoral; textBox9.BackColor = Color.LightCoral;
                    textBox10.BackColor = Color.LightCoral;
                    throw new Exception("ERROR: \nplease review form");
                }     
            }
            catch (Exception ex)
            {
                Error_form ef = new Error_form();
                ef.richTextBox1.Text = ex.Message;
                ef.ShowDialog(this);
            }
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pictureBox2_Click(object sender, EventArgs e)
        {
            ((INV_MDIParent)this.MdiParent).OpenForm(typeof(INV_initpeople_form));
        }

        private void panel3_Paint(object sender, PaintEventArgs e)
        {

        }

        private void panel6_Paint(object sender, PaintEventArgs e)
        {

        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            ls = ((INV_MDIParent)this.MdiParent).appDriver.EditPerson(dataGridView2.CurrentRow.Cells["id"].Value.ToString());
            textBox1.Text = ls[0];
            textBox2.Text = ls[1];
            textBox3.Text = ls[2];
            textBox11.Text = ls[3];
            textBox5.Text = ls[4];
            textBox6.Text = ls[5];
            textBox7.Text = ls[6];
            textBox8.Text = ls[7];

            panel9.Visible = false;
            panel4.Visible = true;
            panel5.Visible = false;
            panel6.Visible = false;
            panel7.Visible = false;
        }
    }
}

/*SELECT fname, lname, mname, title, ext, mobile, ework, epersonal, passw*/